package com.oig.sys.workflow.dao;

import com.oig.sys.workflow.entity.TbFlowInstance;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @author wuxl
 */
public interface ITbFlowInstanceDao extends JpaRepository<TbFlowInstance, Integer> {

	TbFlowInstance getTbFlowInstanceById(Integer id);

	TbFlowInstance getByFlowCodeAndFlowInstanceId(String flowCode, String flowInstanceId);

	@Query("select count(*) from TbFlowInstance f where f.bizType=:bizType and f.bizId=:bizId and f.flowInstanceStatus=:flowInstanceStatus")
	int countBizFlow(@Param("bizType") String bizType, @Param("bizId")String bizId, @Param("flowInstanceStatus")String flowInstanceStatus);

	@Query("from TbFlowInstance f where f.bizType=:bizType and f.bizId=:bizId and f.status='REQ_INIT'")
	TbFlowInstance getInitBizFlow(@Param("bizType") String bizType, @Param("bizId")String bizId);


	@Query("from TbFlowInstance f where f.bizType=:bizType and f.bizId=:bizId and f.flowInstanceStatus='PENDING'")
	TbFlowInstance getPnBizFlow(@Param("bizType") String bizType, @Param("bizId")String bizId);

	@Query("from TbFlowInstance f where f.bizType=:bizType and f.bizId=:bizId")
	TbFlowInstance getBizFlow(@Param("bizType") String bizType, @Param("bizId")String bizId);

}
